package cn.com.connext.scrm.web.rest;

import cn.com.connext.scrm.service.dto.JsonResult;
import cn.com.connext.scrm.service.mapper.CouponService;
import cn.com.connext.scrm.web.rest.req.BasePageReq;
import cn.com.connext.scrm.web.rest.req.CouponPagesReq;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 积分商城 -- 有赞卷相关接口
 */
@RestController
@RequestMapping("/api/shopping/coupon")
public class CouponResource {
    private final Logger log = LoggerFactory.getLogger(CouponResource.class);

    @Autowired
    private CouponService couponService;

    /**
     * 查询有效期内未过期优惠卷
     */
    @PostMapping("/list")
    @ApiOperation(value = "查询有效期内有赞卷", tags = {"有赞卷列表"}, notes = "查询有效期内有赞卷")
    public JsonResult list() {
        log.info("查询有效期内有赞卷");
        return couponService.list();
    }

    @PostMapping("/pages")
    @ApiOperation(value = "有赞卷列表", tags = {"有赞卷列表"}, notes = "有赞卷列表")
    public JsonResult pages(@RequestBody CouponPagesReq req) {
        log.info("有赞卷列表");
        return couponService.pages(req);
    }

    /**
     * 优惠卷
     */
    @PostMapping("/couponList")
    @ApiOperation(value = "优惠卷列表--小程序", tags = {"优惠卷列表"}, notes = "优惠卷列表")
    public JsonResult couponList() {
        log.info("优惠卷列表");
        return couponService.couponList();
    }

    /**
     * 刷新优惠卷列表
     */
    @PostMapping("/refresh")
    @ApiOperation(value = "优惠卷列表刷新", tags = {"优惠卷列表"}, notes = "优惠卷列表刷新")
    public void refresh() {
        log.info("优惠卷列表刷新");
         couponService.refresh();
    }

    /**
     * 优惠卷列表
     */
    @PostMapping("/couponPages")
    @ApiOperation(value = "优惠卷列表", tags = {"优惠卷列表"}, notes = "优惠卷列表刷新")
    public JsonResult couponPages(@RequestBody BasePageReq req) {
        log.info("优惠卷列表刷新");
        return couponService.couponPages(req);
    }

}
